#include <iostream>
#include<fstream>
#include<string>
#include <thread>
#include<mutex>
class logger
{
	std::string name;
	std::string logs;
	std::string times;
public:
	logger(std::string namex, std::string logx,std::string timex):
	name(namex),logs(logx),times(timex){}
	std::string getname() { return name; }
	std::string getlog() { return logs; }
	std::string gettime() { return times; }
	void logname(logger logg) {
		std::ofstream ofs;
		ofs.open(logg.getname(), std::ios::app);
		std::cout << "文件已打开/创建" << std::endl;
		ofs.close();
	}
};
std::string name="zc.txt", logs="zc", times="2023/3/22";
logger logg(name, logs, times);
std::mutex mutexlog;

void write()
{
	std::lock_guard<std::mutex> lock(mutexlog);
	logg.logname(logg);
	std::ofstream ofs;
	ofs.open(logg.getname(), std::ios::app);
	ofs << logg.getname() << " " << logg.getlog() << " " << logg.gettime() << std::endl;
	ofs.close();
}
int main()
{
	std::thread t1(write);
	std::thread t2(write);
	t1.join();
	t2.join();
	return 0;
}
